package com.xuelang.pipeline.artifact.entry.resource;

import com.xuelang.pipeline.artifact.app.resource.ArtifactToolService;
import com.xuelang.pipeline.artifact.client.common.constant.DictDTO;
import com.xuelang.pipeline.artifact.client.common.request.PageParam;
import com.xuelang.pipeline.artifact.client.common.result.ApiResult;
import com.xuelang.pipeline.artifact.client.common.result.PageRecord;
import com.xuelang.pipeline.artifact.client.resource.IArtifactToolService;
import com.xuelang.pipeline.artifact.client.resource.dto.ArtifactAttributeDTO;
import com.xuelang.pipeline.artifact.client.resource.dto.ArtifactToolDTO;
import com.xuelang.pipeline.artifact.client.resource.dto.ArtifactToolQuery;
import com.xuelang.pipeline.artifact.client.resource.dto.PipelineArtifactToolDTO;
import com.xuelang.pipeline.artifact.client.resource.enums.ArtifactToolEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 制品工具web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/artifact-tool")
public class ArtifactToolController implements IArtifactToolService {

    @Autowired
    private ArtifactToolService artifactToolService;

    @Override
    public ApiResult<PageRecord<PipelineArtifactToolDTO>> listArtifactTool() {
        return ApiResult.success(artifactToolService.listArtifactTool());
    }

    @Override
    public ApiResult<PageRecord<ArtifactToolDTO>> pageArtifactToolList(PageParam<ArtifactToolQuery> dtoPageParam) {
        return ApiResult.success(artifactToolService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<ArtifactToolDTO>> conditionalArtifactToolList(ArtifactToolQuery artifactToolQuery) {
        return ApiResult.success(artifactToolService.list(artifactToolQuery));
    }

    @Override
    public ApiResult<Boolean> addArtifactTool(ArtifactToolDTO artifactToolDTO) {
        return ApiResult.success(artifactToolService.add(artifactToolDTO));
    }

    @Override
    public ApiResult<Boolean> updateArtifactTool(ArtifactToolDTO artifactToolDTO) {
        return ApiResult.success(artifactToolService.update(artifactToolDTO));
    }

    @Override
    public ApiResult<Boolean> deleteArtifactTool(String artifactToolUuid) {
        return ApiResult.success(artifactToolService.delete(artifactToolUuid));
    }

    @Override
    public ApiResult<ArtifactToolDTO> queryArtifactTool(String artifactToolUuid) {
        return ApiResult.success(artifactToolService.query(artifactToolUuid));
    }

    @Override
    public ApiResult<String> getArtifactUrlPrefix(String artifactType) {
        return ApiResult.success(artifactToolService.getArtifactUrlPrefix(artifactType));
    }

    @Override
    public ApiResult<ArtifactAttributeDTO> getArtifactGuide(String artifactToolUuid, String userId) {
        return ApiResult.success(artifactToolService.getArtifactGuide(artifactToolUuid, userId));
    }

    @Override
    public ApiResult<List<DictDTO>> queryImageRepoDict() {
        return ApiResult.success(artifactToolService.queryBuildTaskDict(ArtifactToolEnum.ArtifactTypeEnum.DOCKER.name()));
    }

    @Override
    public ApiResult<List<DictDTO>> queryMavenRepoDict() {
        return ApiResult.success(artifactToolService.queryBuildTaskDict(ArtifactToolEnum.ArtifactTypeEnum.MAVEN.name()));
    }

}